﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Atom.Utility;
using System.IO;

namespace WinGenCode
{
    public partial class FrmGenCode : Form
    {
        public FrmGenCode()
        {
            InitializeComponent();
        }

        private void btnGen_Click(object sender, EventArgs e)
        {
            string codeValue = EncryptDecrypt.Encrypt(txtCode.Text);

            txtRealCode.Text = codeValue;

            //string path=System.Windows.Forms.Application.StartupPath + "\\Medlicense.ini";
            //if (File.Exists(path))
            //{
            //    File.Delete(path);
            //}

            //StreamWriter sw = File.CreateText(path);
            //sw.WriteLine(codeValue);
            //sw.Close();
            //sw.Dispose();

            SaveFileDialog sfd = new SaveFileDialog();
            sfd.FileName = "Medlicense.ini";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
               

                SaveFile(sfd.FileName, codeValue);

            }
        }


        protected void SaveFile(string fileName, string content)
        {

            try
            {

                Stream stream = File.OpenWrite(fileName);

                using (StreamWriter writer = new StreamWriter(stream))
                {

                    writer.Write(content);

                }

            }

            catch (IOException ex)
            {

                MessageBox.Show(ex.Message, "Simple Editor", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            }

        }
    }
}
